/**
 * Created by dev on 17/1/19.
 */
import React,{Component} from 'react';
import styles from '../style/styles';//样式
import Header from '../common/header';//头部组件
import * as URLconstant from '../constant/URLconstant'
import Util from '../common/util'
import Icon from 'react-native-vector-icons';//图标库
import Toast from '../common/ToastUtil';
import ReactNative,{
    View,
    Text,
    ScrollView,
    TextInput,
    TouchableOpacity,
    Alert,


} from 'react-native';
export default class refund_goods extends Component {
    // 构造
    constructor(props) {
        super(props);
        // 初始状态
        //this.errorGetOrder=this.errorGetOrder.bind(this);
        this.textInput = this.textInput.bind(this);
        this.successRefund = this.successRefund.bind(this);
        this.errorGetOrder = this.errorGetOrder.bind(this);
    }


    to_Confirm_order() {
        Alert.alert('操作订单', '确认要申请退款?', [
            {text: '取消', onPress: ()=>LOG('点击了取消')},
            {text: '确定', onPress: ()=>this.postRefund()}
        ]);
    }

    postRefund() {
        let user_id = this.props.user_id;
        let order_id = this.props.order_id;
        let phone = this.state.phone;
        let express = this.state.express;
        let Numbers = this.state.Numbers;
        let Reason = this.state.Reason
        let datakey = [];
        if (phone == null || express == null || Numbers == null || Reason == null) {
            Toast.show('请填写完整的信息')
        } else {
            let url = URLconstant.REFUNDGOODS_URL;
            datakey['order_id'] = order_id;
            datakey['user_id'] = user_id;
            datakey['type'] = '2';
            datakey['tel'] = phone;
            datakey['express'] = express;
            datakey['express_order'] = Numbers;
            datakey['reason'] = Reason;
            Util.post(url, datakey, this.successRefund, this.errorGetOrder)
        }

    }

    successRefund(datas) {
        //LOG(datas)
        if (datas.status == 0) {
            Toast.show(datas.msg)
            this.props.Refresh1();
            this.props.navigator.pop();
        } else {
            Toast.show(datas.msg)
        }
    }

    errorGetOrder(err) {
        LOG(err)
    }


    textInput() {
        return (
            <View style={styles.refund_wrap}>
                <View style={styles.refund_top}>
                    <Text style={styles.refund_txt1}>填写退货信息</Text>
                </View>
                <View style={styles.refund_center_wrap}>
                    <View style={styles.refund_txt_wrap}>
                        <Text style={styles.refund_txt2}>联系电话</Text>
                    </View>
                    <View style={{borderWidth:1,borderColor:"#ccc",height:40,justifyContent:'center'}}>
                        <TextInput
                            style={styles.txt_input3}
                            placeholder={'联系电话'}
                            clearButtonMode={'while-editing'}
                            onChangeText={(text)=>this.setState({phone:text})}
                        />
                    </View>
                    <View style={styles.refund_txt_wrap}>
                        <Text style={styles.refund_txt2}>快递公司</Text>
                    </View>
                    <View style={{borderWidth:1,borderColor:"#ccc",height:40,}}>
                        <TextInput
                            style={styles.txt_input3}
                            placeholder={'快递公司'}
                            clearButtonMode={'while-editing'}
                            onChangeText={(text)=>this.setState({express:text})}
                        />
                    </View>
                    <View style={styles.refund_txt_wrap}>
                        <Text style={styles.refund_txt2}>快递单号</Text>
                    </View>
                    <View style={{borderWidth:1,borderColor:"#ccc",height:40}}>
                        <TextInput
                            style={styles.txt_input3}
                            placeholder={'快递单号'}
                            clearButtonMode={'while-editing'}
                            onChangeText={(text)=>this.setState({Numbers:text})}
                        />
                    </View>
                    <View style={styles.refund_txt_wrap}>
                        <Text style={styles.refund_txt2}>退款理由</Text>
                    </View>
                    <View style={{borderWidth:1,borderColor:"#ccc",height:40}}>
                        <TextInput
                            style={styles.txt_input3}
                            placeholder={'退款理由'}
                            clearButtonMode={'while-editing'}
                            onChangeText={(text)=>this.setState({Reason:text})}
                        />
                    </View>
                </View>
                <View style={styles.button_wrap}>
                    <TouchableOpacity style={styles.confirm_btn1} onPress={()=>this.to_Confirm_order()}>
                        <Text style={styles.button_txt}>确认提交</Text>
                    </TouchableOpacity>
                </View>
            </View>
        )
    }

    render() {
        return (
            <View style={{flex:1}}>
                <Header navigator={this.props.navigator} initObj={{title:'申请退货', id:2}}/>
                <View style={{flex:1}}>
                    {this.textInput()}
                </View>

            </View>
        )

    }
}